package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import entity.Course;
import entity.Elective;
import service.ISmsserivce;
import service.impl.SmsserivceImpl;

/**
 * Servlet implementation class StudentAddServlet
 */
@WebServlet(asyncSupported = true, urlPatterns = { "/TeacherAddServlet" })
public class TeacherAddServlet extends HttpServlet {
	
	private ISmsserivce smsservice = new SmsserivceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		
		HttpSession session = request.getSession();
		
		int course_id = Integer.parseInt(request.getParameter("id"));
		String teacher = request.getParameter("teacher");
		String course_name = request.getParameter("course_name");
		int point = Integer.parseInt(request.getParameter("point"));
		String week1 = request.getParameter("week1");
		String day1 = request.getParameter("day1");
		String week2 = request.getParameter("week2");
		String day2 = request.getParameter("day2");
		String time1 = week1 + day1;
		String time2 = week2 + day2;
		String location = request.getParameter("location");
		String limit = request.getParameter("limit");
		String selected=request.getParameter("selected");
		
		Course course = new Course(course_id,course_name,teacher,point,time1,time2,location,limit,selected);
		try {
			int insertCourse = smsservice.insertCourse(course);
			if(insertCourse>0) {
//				<script> alert('操作成功');location.href='TeacherSelectAllServlet'</script>
				response.sendRedirect("TeacherSelectAllServlet");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
